/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Interfaz.java
 *
 * Created on 11/03/2011, 03:46:58 PM
 */

package proyectocompiladores2r;

import AST.Declaracion;
import AST.Errores;

import AST.Simbolo;
import AST.TablaDeSimbolos;
import InterpreteTAC.GrafoCuadruplos;

import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Label;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.SpringLayout;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import proyectocompiladores2r.ParserP;
import proyectocompiladores2r.ScannerProyecto;

/**
 *
 * @author Eddy
 */
public class Interfaz extends javax.swing.JFrame {
    public   int X=500,Y=500;
    public String NombreProyecto;
    public String PathProyecto;
    public GrafoCuadruplos prueba;
    public File Proyecto;
    public LinkedList<GrafoCuadruplos> LCargar=new LinkedList();
    
    DefaultMutableTreeNode top =new DefaultMutableTreeNode("root");
    
    public LinkedList<File> archivos=new LinkedList();
    public LinkedList<TextArea> TAREAS=new LinkedList();
    
    public static String Entrada;

    

    public boolean Guardados=false;


    /** Creates new form Interfaz */
    public Interfaz() {
        

        initComponents();
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("WI");
        //this.jTree1=null;
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ImageIcon iconAP =new ImageIcon("AbrirProyecto.jpg");
        AbrirProyecto = new javax.swing.JButton();
        ImageIcon iconGP=new ImageIcon("GuardarProyecto.jpg");
        GuardarProyecto = new javax.swing.JButton();
        ImageIcon iconAA=new ImageIcon("Agregar Archivo.jpg");
        AgregarArchivo = new javax.swing.JButton();
        ImageIcon iconEA=new ImageIcon("EliminarArchivo.jpg");
        EliminarArchivo = new javax.swing.JButton();
        ImageIcon iconC=new ImageIcon("Correr.jpg");
        Correr = new javax.swing.JButton();
        jTP = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jScrollPane1 = new javax.swing.JScrollPane();
        Tconsola = new javax.swing.JTextArea();
        TFX = new javax.swing.JTextField();
        TFY = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                formKeyTyped(evt);
            }
        });

        AbrirProyecto = new javax.swing.JButton(iconAP);
        AbrirProyecto.setText("B2");
        AbrirProyecto.setText("Abrir Archivo");
        AbrirProyecto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AbrirProyectoActionPerformed(evt);
            }
        });

        GuardarProyecto = new javax.swing.JButton(iconGP);
        GuardarProyecto.setText("B3");
        GuardarProyecto.setText("Cargar TAC");
        GuardarProyecto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GuardarProyectoActionPerformed(evt);
            }
        });

        AgregarArchivo = new javax.swing.JButton(iconAA);
        AgregarArchivo.setText("B4");
        AgregarArchivo.setText("Jugar");
        AgregarArchivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AgregarArchivoActionPerformed(evt);
            }
        });

        EliminarArchivo=new javax.swing.JButton(iconEA);
        EliminarArchivo.setText("B5");
        EliminarArchivo.setText("Optimizar");
        EliminarArchivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EliminarArchivoActionPerformed(evt);
            }
        });

        Correr = new javax.swing.JButton(iconC);
        Correr.setText("B6");
        Correr.setText("Compilar");
        Correr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CorrerActionPerformed(evt);
            }
        });

        jTree1.setModel(new javax.swing.tree.DefaultTreeModel(top));
        jTree1.addTreeExpansionListener(new javax.swing.event.TreeExpansionListener() {
            public void treeExpanded(javax.swing.event.TreeExpansionEvent evt) {
                jTree1TreeExpanded(evt);
            }
            public void treeCollapsed(javax.swing.event.TreeExpansionEvent evt) {
            }
        });
        jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                jTree1ValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jTree1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
        );

        Tconsola.setText("\n");
        Tconsola.setColumns(20);
        Tconsola.setRows(5);
        Tconsola.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                TconsolaInputMethodTextChanged(evt);
            }
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        Tconsola.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TconsolaKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(Tconsola);

        TFX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFXActionPerformed(evt);
            }
        });

        jLabel1.setText("X");

        jLabel2.setText("Y");

        jButton1.setText("Errores");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jMenu1.setText("Archivo");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setText("Abrir Archivo");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Ayuda");

        jMenuItem2.setText("Acerca de");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(AbrirProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(GuardarProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(AgregarArchivo, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(EliminarArchivo, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24)
                        .addComponent(Correr, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TFX, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TFY, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 559, Short.MAX_VALUE)
                                .addGap(234, 234, 234))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jTP, javax.swing.GroupLayout.DEFAULT_SIZE, 787, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(AbrirProyecto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(GuardarProyecto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(AgregarArchivo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(EliminarArchivo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(Correr, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(TFX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)
                        .addComponent(TFY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(jButton1)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTP, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public static void prueba()
    {
        
        try {
            System.in.read();
        } catch (IOException ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    private void GuardarProyectoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GuardarProyectoActionPerformed
        // TODO add your handling code here:
        JFileChooser selectorTAC=new JFileChooser();
        javax.swing.filechooser.FileFilter filtro = new FileNameExtensionFilter("Proyecto (.c)", "c");
        selectorTAC.setFileFilter(filtro);
        selectorTAC.setFileSelectionMode(JFileChooser.FILES_ONLY);
        selectorTAC.showOpenDialog(this);
        if(selectorTAC.getSelectedFile()!=null)
        {
            try {
                File fileTAC=selectorTAC.getSelectedFile();
                Scanner3D sTAC=new Scanner3D(new FileReader(fileTAC));
                Parser3D pTAC=new Parser3D();
                pTAC.setScanner(sTAC);
                
                try {
                    pTAC.parse();
                    pTAC.g.ConectarNodos();
                     int a=10;
                     pTAC.g.NombrePrograma=selectorTAC.getSelectedFile().getName();
                     this.prueba=pTAC.g;
                     this.LCargar.add(pTAC.g);
                     //pTAC.g.BuscarEtiqueta("RobotdeEjemplo_main_").Ejecutar(pTAC.g,null);
                     
                     
                     a=1+1;
                    
                } catch (Exception ex) {
                    Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
            }
         
        }
        
       
    }//GEN-LAST:event_GuardarProyectoActionPerformed

    private void AgregarArchivo(FileReader AR,String NombreA,String PathArchivo,String pt,String mu)
    {
       
      
    }
    
    private void AgregarArchivo()
    {
        
      
      
    }
    
    private void AgregarArchivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AgregarArchivoActionPerformed
        // TODO add your handling code here:
        

        try{
        X=Integer.parseInt(this.TFX.getText());
        Y=Integer.parseInt(this.TFY.getText());
        }
        catch(Exception ex)
        {
        }
        Mundo m1=new Mundo(500,500);
        
        Image a=null;
        
        try
        {
            a=ImageIO.read(new File("tanque1.png"));
        }
        catch(IOException e)
        {
        }
        
        Tanque t1,t2;
        //t1.Programa=this.prueba;
        //m1.agregarTanque(t1);
        
        int i=0;
       for(i=0;i<this.LCargar.size();i++)
        {            
            t1=new Tanque(prueba.NombrePrograma+Integer.toString(i),a,this.LCargar.get(i));
            //t1.Programa=this.LCargar.get(i);
            m1.agregarTanque(t1);
        }
        
      //  t1=new Tanque("Prueba1",a,101,101,0,this.LCargar.get(0));
        
       // m1.agregarTanque(t1);
//        t2=new Tanque("Prueba2",a,400,50,180,this.LCargar.get(1));
        
  //      m1.agregarTanque(t2);
        //m1.agregarTanque(t1);
        //m1.agregarTanque(t2);
        
        m1.setVisible(true);
        JFrame jMundo=new JFrame();
        Thread hilo1=new Thread(m1);
        hilo1.start();
        jMundo.add(m1);
        jMundo.setBounds(40, 40, X+10, Y+10);
        jMundo.setVisible(true);
        //this.LCargar=new LinkedList();
    }//GEN-LAST:event_AgregarArchivoActionPerformed

    private void EliminarArchivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EliminarArchivoActionPerformed
        // TODO add your handling code here:
        JFileChooser selectorTAC=new JFileChooser();
        javax.swing.filechooser.FileFilter filtro = new FileNameExtensionFilter("Proyecto (.c)", "c");
        selectorTAC.setFileFilter(filtro);
        selectorTAC.setFileSelectionMode(JFileChooser.FILES_ONLY);
        selectorTAC.showOpenDialog(this);
        if(selectorTAC.getSelectedFile()!=null)
        {
            try {
                File fileTAC=selectorTAC.getSelectedFile();
                Scanner3D sTAC=new Scanner3D(new FileReader(fileTAC));
                Parser3D pTAC=new Parser3D();
                pTAC.setScanner(sTAC);
                
                try {
                    pTAC.parse();
                    pTAC.g.ConectarNodos();
                     int a=10;
                     pTAC.g.NombrePrograma=selectorTAC.getSelectedFile().getName();                                      
                     pTAC.g.OptimizarSB();                  
                     pTAC.g.EscribirArchivo(selectorTAC.getSelectedFile().getCanonicalPath(), pTAC.g.RegenerarTAC());
                     
                     a=1+1;
                    
                } catch (Exception ex) {
                    Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
            }
         
        }
        
       
    }//GEN-LAST:event_EliminarArchivoActionPerformed

    private void AbrirProyectoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AbrirProyectoActionPerformed
        // TODO add your handling code here:
        JFileChooser CargarProy=new JFileChooser();
        String leerl="",filecomplete="";
        javax.swing.filechooser.FileFilter filtro = new FileNameExtensionFilter("Proyecto (.java)", "java");
        CargarProy.setFileFilter(filtro);
        CargarProy.setFileSelectionMode(JFileChooser.FILES_ONLY);
        CargarProy.showOpenDialog(this);
        if(CargarProy.getSelectedFile()!=null){
        Errores.InicializarTablaDeErrores();
        Proyecto=CargarProy.getSelectedFile();
            try {
                FileReader fr =new FileReader(Proyecto);
                BufferedReader br=new BufferedReader(fr);
                while((leerl=br.readLine())!=null)
                        {
                            filecomplete=filecomplete+"\n"+leerl;
                        }
            } catch (IOException ex) {
                Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }    
        TextArea a=new TextArea();
        a.setEditable(true);
        a.setText(filecomplete);
        a.setEnabled(true);
        archivos.add(Proyecto);
        TAREAS.add(a);
        this.jTP.add(a);
        this.Guardados=true;
    }//GEN-LAST:event_AbrirProyectoActionPerformed
    }
    public void CargarC()
    {
    }
    private void CorrerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CorrerActionPerformed
        // TODO add your handling code here:
        int Indice;
        
        Indice=this.jTP.getSelectedIndex();
        if(Indice>=0)
        {
        InputStream inS= new ByteArrayInputStream(this.TAREAS.get(Indice).getText().getBytes());;
        
                      
                ScannerProyecto scp=new ScannerProyecto(inS);
                ParserP pap=new ParserP();
                pap.setScanner(scp);
                try {
                    pap.CanonicalPath=this.archivos.get(Indice).getParent();
                    pap.parse();
                    //Declaración de variables Globales 
                    pap.TSC.InsertarVG("Vida","int", null);
                    pap.TSC.InsertarVG("Energia","int", null);                    
                    pap.TSC.InsertarVG("Angulo","int", null);                    
                    pap.TSC.InsertarVG("X","int", null);
                    pap.TSC.InsertarVG("Y","int", null);
                    
                    
                    LinkedList<Simbolo> sparameteros=new LinkedList();
                    Simbolo s=new Simbolo("a","int",true);
                    sparameteros.add(s);                    
                    pap.TSC.InsertarMG("Mover","void",sparameteros);                    
                    sparameteros=new LinkedList();
                    s=new Simbolo("a","int",true);
                    sparameteros.add(s);                    
                    pap.TSC.InsertarMG("Disparar","void",sparameteros);
                    sparameteros=new LinkedList();
                    s=new Simbolo("a","int",true);
                    sparameteros.add(s);                    
                    pap.TSC.InsertarMG("MoverAtras","void",sparameteros);
                    sparameteros=new LinkedList();
                    s=new Simbolo("a","int",true);
                    sparameteros.add(s);                    
                    pap.TSC.InsertarMG("Girar","void",sparameteros);
                    sparameteros=new LinkedList();
                    s=new Simbolo("a","int",true);
                    sparameteros.add(s);                    
                    pap.TSC.InsertarMG("Imprimir","void",sparameteros);
                    
                    boolean ret=pap.ins.CargarTS();
                    
                    if(ret)
                    {
                        TextArea a=new TextArea();
                        
                        
                        Entrada=pap.ins.Generar3Direcciones();
                        Entrada=TablaDeSimbolos.GenerarCadenaTemporales(1000,1000)+Entrada;
                        
                        a.setText(Entrada);
                        
                        FileWriter fw=new FileWriter(this.archivos.get(Indice).getParent()+"/"+Proyecto.getName()+"TAC.c");
                        fw.write(Entrada);
                        fw.close();
                        
                        //this.jTP.add(a);
                        //pap.ins.CrearA();
                    }
                    else
                    {
                        System.out.println(":@ :@");
                        //Error
                    }
                    
                } catch (Exception ex) {
                    
                }
            
        }
        //String tabselected=this.jTP.getTitleAt(this.jTP.getSelectedIndex());
        
        
    }//GEN-LAST:event_CorrerActionPerformed

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        // TODO add your handling code here:
        
        if(java.awt.event.KeyEvent.VK_F6==evt.getKeyCode())
        {
        
        }
    }//GEN-LAST:event_formKeyPressed

    private void formKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyTyped
        // TODO add your handling code here:
                System.out.println("----LOL"+evt.getKeyCode());
    }//GEN-LAST:event_formKeyTyped

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        AgregarArchivoActionPerformed(evt);
       
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        javax.swing.JOptionPane.showMessageDialog(this," 1er Proyecto Compliadores 2 \n 2004-13243 \n Eddy Rene Cordon Leiva");
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void TconsolaInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_TconsolaInputMethodTextChanged
        // TODO add your handling code here:
        if(evt.getWhen()==evt.INPUT_METHOD_TEXT_CHANGED)
        System.out.println("Cambio de text");
    }//GEN-LAST:event_TconsolaInputMethodTextChanged

    private void TconsolaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TconsolaKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode()==evt.VK_ENTER)
        {
            int a=this.Tconsola.getText().lastIndexOf("\n");
            String hola=this.Tconsola.getText().substring(a+1);
            this.Entrada=hola;
        }
    }//GEN-LAST:event_TconsolaKeyPressed

private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTree1ValueChanged
// TODO add your handling code here:
   
}//GEN-LAST:event_jTree1ValueChanged

private void jTree1TreeExpanded(javax.swing.event.TreeExpansionEvent evt) {//GEN-FIRST:event_jTree1TreeExpanded
// TODO add your handling code here:
  
}//GEN-LAST:event_jTree1TreeExpanded

private void TFXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFXActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_TFXActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:
                Errores.publicarErrores(this.archivos.get(this.jTP.getSelectedIndex()).getCanonicalPath()+"-html");
                Errores.InicializarTablaDeErrores();
        } catch (IOException ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        Errores.InicializarTablaDeErrores();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Interfaz().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AbrirProyecto;
    private javax.swing.JButton AgregarArchivo;
    private javax.swing.JButton Correr;
    private javax.swing.JButton EliminarArchivo;
    private javax.swing.JButton GuardarProyecto;
    private javax.swing.JTextField TFX;
    private javax.swing.JTextField TFY;
    public static javax.swing.JTextArea Tconsola;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTP;
    private javax.swing.JTree jTree1;
    // End of variables declaration//GEN-END:variables

}